/**
 * @(#)ItemSearch.java, 2010-5-20. 
 * 
 * Copyright 2010 Youdao, Inc. All rights reserved.
 * YOUDAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.rsstuan.search;

import java.util.ArrayList;
import java.util.List;

import com.rsstuan.data.TuanGouWebItem;
import com.rsstuan.service.ItemService;


/**
 *
 * @author guosq
 *
 */
public class ItemSearcher {
    
    private static ItemService itemService = ItemService.getInstance();
    
    public static List<TuanGouWebItem> searchKeyword(String key) {
        List<TuanGouWebItem> items = itemService.getAllAcitveItems();
        List<TuanGouWebItem> targets = new ArrayList<TuanGouWebItem>();
        
        for (TuanGouWebItem item : items) {
            if (item.getTitle() != null && item.getTitle().contains(key)) 
               targets.add(item);
            else if (item.getChannelId() != null && item.getCity().contains(key)) {
                targets.add(item);
            } else if (item.getDescription() != null && item.getDescription().contains(key)) {
                targets.add(item);
            } else if (item.getSiteName() != null && item.getSiteName().contains(key)) {
                targets.add(item);
            }
        }
        return targets;
    }

    public static List<TuanGouWebItem> searchSite(String key) {
        List<TuanGouWebItem> items = itemService.getAllAcitveItems();
        List<TuanGouWebItem> targets = new ArrayList<TuanGouWebItem>();
        
        for (TuanGouWebItem item : items) {
            
            if (item.getSiteName() != null && item.getSiteName().contains(key)) {
                targets.add(item);
            }
        }
        return targets;
    }
}
